home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / comm / bbs / bbbbs85.lha / rexx / ArcMsgs.rexx < prev    next >
OS/2 REXX Batch file  |  1994-11-18  |  10KB  |  431 lines

  1. /* $VER: ArcMsgs.rexx 8.3 (18.11.94)
  2. ⌐ 1990-94 Richard Lee Stockton - FREELY DISTRIBUTABLE
  3. archives unread conference messages into file in users email
  4. */
  5.  
  6. SIGNAL ON BREAK_C
  7. SIGNAL ON ERROR
  8. SIGNAL ON SYNTAX
  9. OPTIONS FAILAT 999999
  10.  
  11. PARSE ARG name' 'single_dir' '.
  12. IF STRIP(single_dir)='' THEN single_dir=0
  13. IF name='' THEN CALL GETOUT(20)
  14.  
  15. CALL TIME('R')
  16.  
  17. figarg='s:CONFIG.BBS'
  18. IF ~EXISTS(figarg) THEN figarg='BBS:BBS_TEXT/CONFIG.BBS'
  19. x=OPEN(f,figarg,'R')
  20. IF x=0 THEN
  21.   DO
  22.     SAY 's:CONFIG.BBS and BBS:BBS/CONFIG.BBS are both missing!'
  23.     CALL GETOUT(21)
  24.   END
  25. data.=''
  26. DO i=1 TO 33
  27.   data.i=READLN(f)
  28. END
  29. CALL CLOSE(f)
  30.  
  31. compos=POS('/*',data.1)
  32. IF compos>0 THEN data.1=LEFT(data.1,compos-1)
  33. bbsname = STRIP(data.1)
  34. sysop   = WORD(data.2,1)
  35. bbspath = WORD(data.6,1)
  36. IF ~EXISTS(bbspath) THEN
  37.   DO
  38.     SAY bbspath 'does not exist!'
  39.     CALL GETOUT(22)
  40.   END
  41. testchar=RIGHT(bbspath,1)
  42. IF testchar~='/' & testchar~=':' THEN bbspath=bbspath'/'
  43. msgpath = WORD(data.7,1)
  44. IF ~EXISTS(msgpath) THEN
  45.   DO
  46.     SAY msgpath 'does not exist!'
  47.     CALL GETOUT(23)
  48.   END
  49. testchar=RIGHT(msgpath,1)
  50. IF testchar~='/' & testchar~=':' THEN msgpath=msgpath'/'
  51. msgpath=msgpath'MSG'
  52. IF WORD(lynes.25,1)=1 THEN scratch=bbspath'Scratch'
  53. ELSE scratch='RAM:Scratch'
  54. extension=WORD(data.32,1)
  55. arccom=data.33
  56. compos=POS('/*',data.33)
  57. IF compos>0 THEN data.33=LEFT(data.33,compos-1)
  58. arccom=STRIP(data.33)
  59. IF LEFT(extension,1)~='.' THEN
  60.   DO
  61.     extension='.lzh'
  62.     arccom='lharc -m m'
  63.   END
  64.  
  65. CALL CLOSE(STDOUT)
  66. CALL OPEN(STDOUT,scratch'/ArcMsgs.STDOUT','W')
  67. SAY STRIP(SUBSTR(SOURCELINE(1),3))
  68. SAY
  69.  
  70. DO i=1
  71.   IF GETCLIP('BBS_MSGS'i)='' THEN  /* info clip for external STOP */
  72.     DO
  73.       CALL SETCLIP('BBS_MSGS'i,name)
  74.       CALL SETCLIP('BBS_STOP_MSGS'i)
  75.       clipnum=i
  76.       LEAVE i
  77.     END
  78. END
  79.  
  80. x=OPEN(f,bbspath'Users/'name,'R')
  81. IF x=0 THEN
  82.   DO
  83.     CALL DELAY(150)
  84.     x=OPEN(f,bbspath'Users/'name,'R')
  85.     IF x=0 THEN
  86.       DO
  87.         SAY name 'user file is missing!'
  88.         CALL GETOUT(24)
  89.       END
  90.   END
  91. data.=''
  92. DO i=1 TO 25
  93.   data.i=READLN(f)
  94. END
  95. CALL CLOSE(f)
  96. level=data.20%1
  97. lastread.=0
  98.  
  99. x=GETCLIP('BBS_'name'_22')
  100. IF x~='' THEN
  101.   DO
  102.     data.22=x
  103.     CALL SETCLIP('BBS_'name'_22')
  104.   END
  105.  
  106. msg.=''
  107. IF readopen(bbspath'Lists/Conferences') THEN
  108.   DO
  109.     DO i=1
  110.       line=READLN(f)
  111.       IF line='END' THEN BREAK
  112.       IF EOF(f) THEN BREAK
  113.       num=WORD(line,1)
  114.       IF DATATYPE(num,'N') THEN msg.num=WORD(line,2)
  115.     END
  116.     CALL CLOSE(f)
  117.   END
  118.  
  119. CALL SETCLIP('BBS_MSGS')
  120. CALL PRAGMA('P',-2)         /* lower the priority of this task */
  121.  
  122. oldt=0
  123. count=0
  124. lastm=0
  125. archives=1
  126. CALL open_new()
  127.  
  128. filepath=bbspath'EmailFiles/'name
  129. CALL MAKEDIR(filepath)
  130. arcname=filepath'/BBBBS_'lastm
  131. IF GETCLIP('BBS_'name)~='' THEN arcname=filepath'/Messages'
  132. CALL open_arc()
  133. CALL newmsgs()
  134. CALL CLOSE(a)
  135. CALL DELAY(28)
  136. IF WORD(STATEF(arcname),2)<80 THEN CALL GETOUT(24)
  137. CALL write_msg()
  138. CALL GETOUT(0)
  139. EXIT
  140.  
  141.  
  142.  
  143. /* Functions */
  144.  
  145.  
  146. write_msg:
  147. IF GETCLIP('BBS_'name)~='' THEN RETURN
  148. CALL PRAGMA('P',0)         /* normal priority */
  149. ADDRESS COMMAND arccom arcname||extension arcname
  150. IF ~EXISTS(arcname||extension) THEN CALL GETOUT(27)
  151. CALL PRAGMA('P',-2)
  152. x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  153. IF x=0 THEN CALL GETOUT(26)
  154. CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm||extension)
  155. CALL WRITELN(f,' From: BBBBS')
  156. CALL WRITELN(f,'   To: 'name)
  157. CALL WRITELN(f,' Subj: 'subj)
  158. CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  159. CALL WRITELN(f,LEFT('=',75,'='))
  160. temp='Here are the archived new messages you requested'
  161. IF WORD(finfo,2)>1400000 THEN temp=temp', part' archives-1
  162. CALL WRITELN(f,temp)
  163. t=(.5+TIME('E'))%1
  164. t=t-oldt
  165. oldt=t+oldt
  166. min=t%60
  167. hrs=min%60
  168. min=min//60
  169. sec=t//60
  170. temp=' - It took'
  171. IF hrs>1 THEN temp=temp hrs 'hours'
  172. ELSE IF hrs=1 THEN temp=temp '1 hour'
  173. IF min>1 THEN temp=temp min 'minutes'
  174. ELSE IF min=1 THEN temp=temp '1 minute'
  175. IF sec=1 THEN temp=temp '1 second'
  176. ELSE IF sec>0 THEN temp=temp sec 'seconds'
  177. temp=temp 'to compile these messages -'
  178. CALL WRITELN(f,temp)
  179. CALL CLOSE(f)
  180. newmess='Your archived messages are waiting in Email.'
  181. IF GETCLIP('BBS_level')~='' & WORD(GETCLIP('BBS_lastcaller'),1)=name THEN
  182.   DO
  183.     oldmess=GETCLIP('BBS_MESSAGE')
  184.     IF oldmess~='' THEN oldmess=oldmess||'0D0A'x
  185.     CALL SETCLIP('BBS_MESSAGE',oldmess||newmess)
  186.   END
  187. IF GETCLIP('BBS_LOCAL')=name THEN CALL SETCLIP('BBS_LOCAL_MSG',newmess)
  188. RETURN
  189.  
  190.  
  191. open_new:
  192. subj='All New Conference Messages'
  193. IF single_dir>0 THEN subj=msg.single_dir' conference messages'
  194. IF WORD(finfo,2)>1400000 THEN subj=subj', part' archives
  195. IF GETCLIP('BBS_'name)='' THEN
  196.   DO
  197.     x=OPEN(f,bbspath'Numbers/LastMail','R')
  198.     IF x=0 THEN
  199.       DO
  200.         CALL DELAY(100)
  201.         x=OPEN(f,bbspath'Numbers/LastMail','R')
  202.       END
  203.     IF x=0 THEN
  204.       DO
  205.         IF lastm=0 THEN lastm=1
  206.         ELSE lastm=lastm+1
  207.       END
  208.     ELSE lastm=READLN(f)+1
  209.     CALL CLOSE(f)
  210.     ADDRESS COMMAND 'ECHO >'bbspath'Numbers/LastMail 'lastm
  211.     x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'W')
  212.     IF x=0 THEN CALL GETOUT(26)
  213.     CALL WRITELN(f,' Mail: 'lastm'   FILE: BBBBS_'lastm)
  214.     CALL WRITELN(f,' From: BBBBS')
  215.     CALL WRITELN(f,'   To: 'name)
  216.     CALL WRITELN(f,' Subj: 'subj)
  217.     CALL WRITELN(f,' Date: 'DATE('W') DATE() TIME('C'))
  218.     CALL WRITELN(f,LEFT('=',75,'='))
  219.     CALL WRITELN(f,'Here are the new messages you requested.')
  220.     CALL WRITELN(f,'The collection process was interrupted.')
  221.     CALL CLOSE(f)
  222.   END
  223. RETURN
  224.  
  225.  
  226. countcheck:
  227. PARSE ARG fname' '.
  228. IF ~readopen(fname) THEN RETURN(cknum)
  229. retval=STRIP(READLN(f))
  230. CALL CLOSE(f)
  231. IF ~DATATYPE(retval,'N') THEN retval=0
  232. RETURN(retval)
  233.  
  234.  
  235. newmsgs:
  236. IF single_dir>0 THEN
  237.   DO
  238.     msgdir=single_dir
  239.     CALL readmsg()
  240.     RETURN
  241.   END
  242. CALL WRITELN(a,'Scanning all Conferences for new messages..')
  243. DO newi=1 TO level
  244.   IF msg.newi='' THEN ITERATE newi
  245.   msgdir=newi
  246.   CALL readmsg()
  247. END
  248. RETURN
  249.  
  250.  
  251. readmsg:
  252. IF msg.msgdir='' | FIND(data.21,msgdir)>0 THEN RETURN;   /* sysop excluded */
  253. IF WORD(data.22,msgdir)=-1 THEN RETURN;  /*  user excluded */
  254. IF DATATYPE(WORD(data.22,msgdir),'N') THEN
  255.   lastread.msgdir=WORD(data.22,msgdir)
  256. IF STRIP(SHOWDIR(msgpath||msgdir))='' THEN RETURN
  257. lstwrt=countcheck(bbspath'Numbers/LastMessage'msgdir 0)
  258. frstwrt=countcheck(bbspath'Numbers/FirstMessage'msgdir 0)
  259. temp=''
  260. IF lastread.msgdir>=lstwrt THEN
  261.   DO
  262.     lastread.msgdir=lstwrt
  263.     RETURN
  264.   END
  265. CALL WRITELN(a,'Entering' msg.msgdir 'Message Conference..')
  266. IF OPEN(c,msgpath||msgdir'.txt','R')~=0 THEN
  267.   DO i=1
  268.     line=READLN(c)
  269.     IF EOF(c) THEN LEAVE i
  270.     CALL WRITELN(a,line)
  271.   END
  272. CALL CLOSE(c)
  273. dirname=msgpath||msgdir
  274. msglist.=0 /* set read to 0, unread to 1, and reply >=2 */
  275. firstmess=999999
  276. testlist=SHOWDIR(dirname)
  277. DO i=1 TO WORDS(testlist)
  278.   test=WORD(testlist,i)
  279.   IF test>lastread.msgdir THEN msglist.test=1
  280.   IF test<firstmess THEN firstmess=test
  281. END
  282. IF firstmess=999999 THEN firstmess=0
  283. CALL countcheck(bbspath'Numbers/FirstMessage'msgdir firstmess)
  284. msgstatus=1
  285. DO msgloop=1
  286.   lastreadnum=lastread.msgdir
  287.   DO WHILE msglist.lastreadnum=0 & lastreadnum<lstwrt
  288.     lastreadnum=lastreadnum+1
  289.   END
  290.   lastread.msgdir=lastreadnum
  291.   IF lastreadnum=lstwrt & msglist.lstwrt=0 THEN RETURN
  292.   DO mess=lastread.msgdir TO lstwrt+1
  293.     IF msglist.mess~=msgstatus THEN ITERATE mess
  294.     IF msgstatus>1 THEN CALL WRITELN(a,'Following the thread, level' msgstatus-1'.')
  295.     msglist.mess=0
  296.     arg=dirname'/'mess
  297.     IF ~EXISTS(arg) THEN
  298.       DO
  299.         CALL WRITELN(a,'Message number' mess 'is missing.')
  300.         ITERATE mess
  301.       END
  302.     IF ~readopen(arg) THEN ITERATE mess
  303.     firstline  = READLN(f)
  304.     secondline = READLN(f)
  305.     thirdline  = READLN(f)
  306.     forthline  = READLN(f)
  307.     CALL CLOSE(f)
  308.     IF WORDS(firstline)>2 THEN  /* if replies, change their num to >1 */
  309.       DO
  310.         thread=SUBSTR(firstline,WORDINDEX(firstline,4))
  311.         DO tindx=1 TO WORDS(thread)
  312.           test=WORD(thread,tindx)
  313.           IF msglist.test~=0 THEN msglist.test=msgstatus+1
  314.         END
  315.       END
  316.     CALL add_msg(arg)
  317.     IF thread~='' THEN
  318.        DO
  319.          thread=''
  320.          msgstatus=msgstatus+1
  321.        END
  322.   END
  323.   IF msgstatus>1 THEN msgstatus=msgstatus-1
  324. END
  325. RETURN
  326.  
  327.  
  328. readopen:
  329. PARSE ARG fname
  330. ok=OPEN(f,fname,'R')
  331. IF ok~=0 THEN RETURN(1)
  332. SAY fname 'failed to open for reading!'
  333. RETURN(0)
  334.  
  335.  
  336. open_arc:
  337. CALL CLOSE(a)
  338. x=OPEN(a,arcname,'W')
  339. IF x=0 THEN CALL GETOUT(30)
  340. temp='= Custom archived for' name
  341. IF WORD(finfo,2)>1400000 THEN temp=temp', part' archives
  342. CALL WRITELN(a,temp)
  343. CALL WRITELN(a,'=' bbsname  'conference messages to' DATE('W') DATE() TIME('C'))
  344. CALL WRITELN(a,'')
  345. RETURN
  346.  
  347.  
  348. add_msg:
  349. ARG addname .
  350. count=count+1
  351. IF count//5=0 THEN
  352.   DO
  353.     t=GETCLIP('BBS_STOP_MSGS'clipnum)
  354.     IF t~='' THEN CALL cleanup(t)
  355.   END
  356. finfo=STATEF(arcname)
  357. IF WORD(finfo,2)>1400000 THEN
  358.   DO
  359.     archives=archives+1
  360.     CALL WRITELN(a,CENTER('=== continued in part' archives '. ===',75))
  361.     IF GETCLIP('BBS_'name)~='' THEN
  362.       DO
  363.         IF EXISTS('Messages') THEN CALL RENAME('Messages','Mess1')
  364.         arcname=filepath'/Mess'archives
  365.       END
  366.     ELSE
  367.       DO
  368.         CALL write_msg()
  369.         x=OPEN(f,bbspath'Numbers/LastMail','R')
  370.         IF x~=0 THEN lastm=READLN(f)+1
  371.         ELSE lastm=lastm+1
  372.         CALL CLOSE(f)
  373.         ADDRESS COMMAND 'echo >'bbspath'Numbers/LastMail 'lastm
  374.         arcname=filepath'/BBBBS_'lastm
  375.         CALL open_new()
  376.       END
  377.     CALL open_arc()
  378.   END
  379. x=OPEN(b,addname,'R')
  380. IF x=0 THEN SAY addname 'failed to open for reading!'
  381. ELSE
  382.   DO
  383.     data=READCH(b,65000)
  384.     CALL CLOSE(b)
  385.     CALL WRITECH(a,data)
  386.   END
  387. CALL WRITELN(a,'')
  388. CALL WRITELN(a,'')
  389. RETURN
  390.  
  391.  
  392. cleanup:
  393. ARG t2 .
  394. CALL CLOSE(a)
  395. SAY 'User aborted!'
  396. IF t2='DELETE' THEN
  397.   DO
  398.     IF GETCLIP('BBS_'name)~='' THEN temp=bbspath'EmailFiles/'name'/Mess'
  399.     ELSE temp=LEFT(arcname,LENGTH(arcname)-4)
  400.     ADDRESS COMMAND 'c:delete' temp'#?'
  401.     x=OPEN(f,bbspath'Email/'name'/BBBBS.'lastm,'A')
  402.     IF x~=0 THEN
  403.       DO
  404.         CALL WRITELN(f,'')
  405.         CALL WRITELN(f,'*** This process aborted' DATE() 'at' TIME('C') '***')
  406.         CALL WRITELN(f,'*** No data file exists, not even a partial one. ***')
  407.         CALL CLOSE(f)
  408.       END
  409.   END
  410. CALL GETOUT(0)
  411. RETURN
  412.  
  413.  
  414. BREAK_C:
  415. SAY 'BREAK_C at line' SIGL
  416. CALL GETOUT(1)
  417.  
  418.  
  419. GETOUT:
  420. ARG errorout
  421. ERROR:
  422. SYNTAX:
  423. IF RC='RC' THEN RC=0
  424. IF errorout>0 | RC>0 THEN SAY 'Error:' errorout'  RC='RC'  SIGL='SIGL
  425. CALL SETCLIP('BBS_MSGS')
  426. CALL SETCLIP('BBS_MSGS'clipnum)
  427. CALL SETCLIP('BBS_STOP_MSGS'clipnum)
  428. EXIT errorout
  429.  
  430. /* end of ArcMsgs.rexx */
  431.